package net.jalbum.filters;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.JButton;

import se.datadosen.jalbum.Msg;


public class MultipleResizableObjectControl extends ResizableObjectControl {
	/**
	 *
	 */
	private static final long serialVersionUID = 4611739482769720963L;
	protected MultipleResizableObjectPanel multipleResizableObjectPanel;
	protected JButton addButton;
	protected JButton removeButton;
	protected JButton nextButton;
	protected JButton previousButton;

	public MultipleResizableObjectControl(){
	}

	public MultipleResizableObjectControl(MultipleResizableObjectPanel multipleResizableObjectPanel){
		init(multipleResizableObjectPanel);
		addMultipleControls();
	}

	protected void init(MultipleResizableObjectPanel multipleResizableObjectPanel) {
		this.multipleResizableObjectPanel = multipleResizableObjectPanel;
		super.init(multipleResizableObjectPanel);
	}

	protected void addMultipleControls(){
		addButton = new JButton(Msg.getString(this,"filters.multiple.add"));
		removeButton = new JButton(Msg.getString(this,"filters.multiple.remove"));
		nextButton = new JButton(Msg.getString(this,"filters.multiple.next"));
		previousButton = new JButton(Msg.getString(this,"filters.multiple.previous"));

		addButton.addActionListener(this);
		removeButton.addActionListener(this);
		nextButton.addActionListener(this);
		previousButton.addActionListener(this);

		previousButton.setEnabled(false);
		nextButton.setEnabled(false);
		removeButton.setEnabled(false);

		this.add(addButton);
		this.add(removeButton);
		this.add(previousButton);
		this.add(nextButton);
	}

	public void actionPerformed(ActionEvent e) {
		super.actionPerformed(e);
		if (e.getSource()== addButton){
			multipleResizableObjectPanel.addObject();
			checkButtons();
		}else if (e.getSource()== removeButton){
			multipleResizableObjectPanel.removeObject();
			checkButtons();
		}else if (e.getSource()== previousButton){
			multipleResizableObjectPanel.previousObject();
		}else if (e.getSource()== nextButton){
			multipleResizableObjectPanel.nextObject();
		}
	}

	protected void checkButtons(){
		if(multipleResizableObjectPanel.getObjectVector().size()>1){
			previousButton.setEnabled(true);
			nextButton.setEnabled(true);
			removeButton.setEnabled(true);
		}else{
			previousButton.setEnabled(false);
			nextButton.setEnabled(false);
			removeButton.setEnabled(false);
		}
	}


	public void keyPressed(KeyEvent e) {
	}

	public void keyReleased(KeyEvent e) {
	}

	public void keyTyped(KeyEvent e) {
	}
}
